<script setup>
import { ref, computed } from 'vue'

const props = defineProps({
  data: {
    type: Array,
    default: []
  },
  status: {
    type: String,
    default: ''
  },
  historyKey: {
    type: String,
    default: ''
  }
})

const lists = ref(
  props.data.map((v, i) => {
    return {
      ...v,
      active: i === 0 ? true : false
    }
  })
)

const actLeftItem = (index) => {
  lists.value.forEach((v, i) => {
    if (index === i) {
      v.active = true
    } else {
      v.active = false
    }
  })
}

const actItem = computed(() => {
  const actArr = lists.value.filter((v) => v.active)
  return actArr.length ? actArr[0] : null
})

const submitForm = () => {
  return { data: [...props.data], statusData: props.status, key: props.historyKey }
}

defineExpose({
  submitForm
})
</script>

<template>
  <div class="history-com">
    <div class="left-box">
      <div :class="{ 'left-item': true, active: item.active }" v-for="(item, index) in lists" :key="index" @click="actLeftItem(index)">
        次数: {{ index + 1 }}--{{ item.time }}
      </div>
    </div>

    <div v-if="actItem" class="right-box">
      <div class="history-red">
        <div class="title">
          红队 <span class="sum redSum">({{ actItem.redSum }})</span>
        </div>
        <div class="person-list">
          <div class="person-item" v-for="(item2, index2) in actItem.red" :key="index2">
            <div class="name">{{ item2.name }}</div>
            <div class="money">{{ item2.money }}</div>
            <div class="score">{{ item2.score }}</div>
          </div>
        </div>
      </div>
      <div class="history-blue">
        <div class="title">
          蓝队 <span class="sum blueSum">({{ actItem.blueSum }})</span>
        </div>
        <div class="person-list">
          <div class="person-item" v-for="(item2, index2) in actItem.blue" :key="index2">
            <div class="name">{{ item2.name }}</div>
            <div class="money">{{ item2.money }}</div>
            <div class="score">{{ item2.score }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.history-com {
  width: 700px;
  display: flex;

  .left-box {
    margin-right: 30px;

    .left-item {
      padding: 8px;
      background-color: #e2e2e2;
      border-radius: 3px;
      margin-bottom: 10px;
      cursor: pointer;
    }

    .left-item.active {
      font-weight: bold;
      background-color: var(--mainColor);
      color: #fff;
    }
  }

  .right-box {
    display: flex;
    flex: 1;
    justify-content: space-between;
    // padding: 20px;

    .history-red {
      .title {
        font-size: 18px;
        color: rgba(245, 83, 19, 0.938);
        font-weight: bold;
        margin-bottom: 10px;
      }
    }

    .history-blue {
      .title {
        font-size: 18px;
        color: rgba(60, 29, 236, 0.938);
        font-weight: bold;
        margin-bottom: 10px;
      }
    }

    .person-list {
      .person-item {
        margin-bottom: 5px;
        display: flex;

        .name {
          margin-right: 20px;
        }

        .money {
          margin-right: 20px;
        }
      }
    }
  }
}
</style>
